home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from __future__ import with_statement
- from itertools import count
- import functools
- import logging
- import os
- import threading
- import time
- log = logging.getLogger('util.primitives.synch')
-
- def lock(f):
-
- def wrapper1(instance, *args, **kw):
- if not hasattr(instance, '_lock'):
-
- try:
- instance._lock = threading.RLock()
- except AttributeError:
- raise NotImplementedError, '%s needs a _lock slot' % instance.__class__.__name__
- except:
- None<EXCEPTION MATCH>AttributeError
-
-
- None<EXCEPTION MATCH>AttributeError
- instance._lock.__enter__()
-
- try:
- val = f(instance, *args, **kw)
- finally:
- pass
-
- return val
-
- wrapper1 = (functools.wraps(f),)(wrapper1)
- return wrapper1
-
-
- class RepeatCheck(object):
-
- def __init__(self, idfunc = None):
- self.ids = sentinel
- if idfunc is None:
- idfunc = id
-
- self.id = idfunc
-
-
- def __call__(self, *x):
- if x == tuple():
- self.ids = sentinel
- return None
- elif len(x) != 1:
- raise TypeError('takes one argument')
-
-
- try:
- newids = [ self.id(a) for a in x ]
- except TypeError:
- newids = [
- self.id(a)]
-
- changed = newids != self.ids
- self.ids = newids
- return changed
-
-
-
- def repeat_guard(func):
- guard = RepeatCheck()
-
- def wrapper(src, attr, old, new):
- if guard(src):
- return None
-
- return func(src, attr, old, new)
-
- return wrapper
-
-
- class HangingThreadDaemon(threading.Thread):
- ids = count()
-
- def __init__(self, wait = 3, sysexit = False):
- threading.Thread.__init__(self, name = 'HangingThreadDaemon %d' % self.ids.next())
- self.wait = wait
- self.sysexit = sysexit
- self.setDaemon(True)
-
-
- def run(self):
- time.sleep(self.wait)
- threads = list(threading.enumerate())
- if threads:
- print 'Remaining non-daemon threads:'
- for thread in threads:
- if not thread.isDaemon():
- print ' ', thread
- continue
-
-
- collect_garbage_and_report()
- if self.sysexit:
- print 'forcing shutdown...'
- os._exit(1)
-
-
-
-
- def collect_garbage_and_report():
- import gc
- garbage_count = gc.collect()
- if garbage_count > 0:
- log.info('Garbage collected. ' + str(garbage_count) + ' unreachable objects')
- if garbage_count:
- log.info('Garbage left (only first 20 listed): %r', gc.garbage[:20])
-
-
-
- if __name__ == '__main__':
- import doctest
- doctest.testmod(verbose = True)
-
-